function main(data) {
  const head = data[0];

  const rowLen = head.length;

  let currentMonth;
  let currentGoods;

  const result = [
    ['物料维度', '供方', '采购方', '单位', '当月均价', '当月数量'],
  ];
  // 遍历body
  for (let i = 1; i < data.length; i += 1) {
    const row = data[i];
    const rowInfo = {};
    const companyMap = new Map();
    for (let j = 0; j < rowLen; j += 1) {
      if (j === 0) {
        if (row[j]) {
          currentMonth = row[j];
        }
        rowInfo.month = currentMonth;
      } else if (j === 1) {
        if (row[j]) {
          currentGoods = row[j];
        }
        rowInfo.goods = currentGoods;
      } else if (j === 2) {
        rowInfo.supplier = row[j];
      } else if (j === 3) {
        rowInfo.unit = row[j];
      } else if (row[j]) {
        const currentHead = head[j];
        const currentName = currentHead.slice(0, -4);
        let target = companyMap.get(currentName);
        if (!target) {
          target = { orderBy: currentName };
          companyMap.set(currentName, target);
        }
        if (currentHead.includes('单价')) {
          target.price = row[j];
        } else {
          target.quantity = row[j];
        }
        const next = row[j + 1];
        if (!next) {
          result.push([
            rowInfo.goods,
            rowInfo.supplier,
            target.orderBy,
            rowInfo.unit,
            target.price || '/',
            target.quantity || '/',
          ]);
        } else {
          const nextHead = head[j + 1];
          const nextName = nextHead.slice(0, -4);
          if (nextName !== currentName) {
            result.push([
              rowInfo.goods,
              rowInfo.supplier,
              target.orderBy,
              rowInfo.unit,
              target.price || '/',
              target.quantity || '/',
            ]);
          }
        }
      }
    }
  }

  console.log('debug-> ~ main ~ result:', result);
  return result;
}

export default main;
